package com.example.servlet;

import com.example.dao.CourseDao;
import com.example.pojo.Course;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/doCourse")
public class CourseServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CourseDao dao=new CourseDao();
        PrintWriter out = resp.getWriter();
        Course course=new Course();
        course.setDate(req.getParameter("date"));
        course.setCourse_name(req.getParameter("name"));
        course.setCourse_content(req.getParameter("content"));
        course.setTeacher(req.getParameter("teacher"));
        if(dao.addCourse(course)) out.println("<h3>添加课程成功</h3>");
        else out.println("<h3>添加课程失败</h3>");

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
}
